﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DTO;
using BUS;

namespace MasterPageGroupF3
{
    public partial class DangKyHCM : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Session["idCity"] = 2;                     
        }

        protected void btnDangKy_Click(object sender, EventArgs e)
        {                        
            CaptchaControl1.ValidateCaptcha(txtCaptcha.Text);
            if (CaptchaControl1.UserValidated)
            {
                MEMBER memNew = new MEMBER();
                if (MEMBERBUS.TonTai_Email(txtEmail.Text) == true)
                {
                    Response.Write("<script language='javascript'>alert('Email đã tồn tại.');</script>");
                    return;
                }

                if (MEMBERBUS.TonTai_UserName(txtTenThanhVien.Text) == true)
                {
                    Response.Write("<script language='javascript'>alert('Tên thành viên đã tồn tại.');</script>");
                    return;
                }
                memNew.EMAIL = txtEmail.Text;                
                memNew.USERNAME = txtTenThanhVien.Text;
                memNew.PASSWORD = txtMatKhau.Text;
                memNew.GENDER = 0;
                if (rNu.Checked == true)
                    memNew.GENDER = 1;
                memNew.NAME = txtHoTen.Text;
                memNew.BIRTHDAY = DateTime.Parse(txtNgaySinh.Text);                
                int res = MEMBERBUS.ThemThanhVien(memNew);
                if (res == 0)
                {
                    Response.Write("<script language='javascript'>alert('Chúc mừng bạn "+ txtTenThanhVien.Text + " đã đăng ký thành công.');</script>");                    
                }
                else
                {
                    Response.Write("<script language='javascript'>alert('Dang ky that bai.');</script>");
                }
            }
            else 
            {
                Response.Write("<script language='javascript'>alert('Nhập sai mã xác nhận.');</script>");
            }            
        }

        protected void cbNhaCC_CheckedChanged(object sender, EventArgs e)
        {
            if (cbNhaCC.Checked == true)
            {
                Response.Redirect("NhaCungCapDangKy.aspx");
            }
        }                      
    }
}